package com.distributeredis.redis_springboot.springreflect.demotest.controller;

import com.distributeredis.redis_springboot.springreflect.demotest.vo.People;
import com.distributeredis.redis_springboot.springreflect.demotest.vo.PeopleDept;
import com.distributeredis.redis_springboot.springreflect.demotest.vo.PeopleFamary;
import com.distributeredis.redis_springboot.springreflect.utils.ReflectUtils;
import org.springframework.cglib.core.CollectionUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Collection;
import java.util.List;

@RestController
@RequestMapping("reflect")
public class ReflectController {
    // 测试通用模式
    @PostMapping("/test2")
    public void testFelect2(@RequestBody People people) throws IllegalAccessException {
        System.out.println(people.toString());
        // 去除空格
        ReflectUtils.ObjectCommonFieldTrim(people);
        PeopleFamary peopleFamary = people.getPeopleFamary();
        if(peopleFamary != null) {
            ReflectUtils.ObjectCommonFieldTrim(peopleFamary);
        }
        List<PeopleDept> peopleDepts = people.getPeopleDepts();
        if(peopleDepts != null && peopleDepts.size() > 0) {
            for (PeopleDept peopleDept : peopleDepts) {
                ReflectUtils.ObjectCommonFieldTrim(peopleDept);
            }
        }
        System.out.println(people.toString());
    }
    // 单个模式
    @PostMapping("/test")
    public void testFelect(@RequestBody People people) throws IllegalAccessException {
        ReflectUtils.ObjectFieldTrim(people);
        System.out.println(people.toString());
    }
}
